package com.baosight.sczx.zm.cs.service;

import java.util.List;

import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.zm.basetools.TablePk;
import com.baosight.sczx.common.zm.cInterface.CmesConstants;
import com.baosight.sczx.common.zm.cInterface.Department;
import com.baosight.sczx.zm.cs.domain.ZMCSSystemSettingCL;

/**
 * 现场安全设置
 * <p>Title: ServiceZMCS14.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 严洪浩
 * @version 1.0
 * <pre>Histroy:
 *          2011-7-18 上午01:38:36  严洪浩  Create
 *</pre>
 */
public class ServiceZMCS14 extends ServiceEPBase {

	/**
	 * 初始化现场安全参数设置数据
	 * <p>Function: initLoad</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCS23</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-1-15下午02:26:48 严洪浩
	 * </p>
	 *
	 */
	@Override
	public EiInfo initLoad(EiInfo inInfo) {
		EiInfo outInfo = super.query(inInfo, "ZMCSSystemSettingCL.query", new ZMCSSystemSettingCL());
		outInfo.addBlock(Department.getInstance().getConstructionUnit(false));
		return outInfo;
	}
	
	/**
	 * 修改
	 * <p>Function: update</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCS23</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-1-15下午03:58:11 严洪浩
	 * </p>
	 *
	 */
	@SuppressWarnings("rawtypes")
	@Override
	public EiInfo update(EiInfo inInfo) {
		List _check = dao.query("ZMCSSystemSettingCL.query", null);
		EiInfo outInfo;
		if(_check.size() > 0) {
			outInfo = super.update(inInfo, "ZMCSSystemSettingCL.update");
		}
		else {
			inInfo.setCell("result", 0, "fdKeyId", TablePk.getInstance().getNextValue("T_CI_SAFETYSETTING"));
			outInfo = super.insert(inInfo, "ZMCSSystemSettingCL.insert");
		}
		this.changeInitialData(outInfo);//如果修改成功则重新刷新数据
		return outInfo;
	}
	
	/**
	 * 如果修改成功则刷新数据
	 * <p>Function: changeInitialData</p>
	 * <p>Description: </p>
	 * <p>return value:void</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-1-18下午02:59:02 严洪浩
	 * </p>
	 *
	 */
	private void changeInitialData(EiInfo outInfo){
		if(outInfo != null && outInfo.getStatus() != -1) {
			CmesConstants.SYSTEMSETTING_CL = 1;
		}
	}
}
